package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.system.MeterInfo2;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IMeterInfo2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 终端信息Controller
 *
 * @author zjw
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/system/meterinfo2")
public class MeterInfo2Controller extends BaseController {
    @Autowired
    private IMeterInfo2Service meterInfo2Service;

    /**
     * 查询终端信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeterInfo2 meterInfo2) {
        startPage();
        List<MeterInfo2> list = meterInfo2Service.selectMeterInfoList(meterInfo2);
        return getDataTable(list);
    }

    /**
     * 导出终端信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "终端信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeterInfo2 meterInfo2) {
        List<MeterInfo2> list = meterInfo2Service.selectMeterInfoList(meterInfo2);
        ExcelUtil<MeterInfo2> util = new ExcelUtil<MeterInfo2>(MeterInfo2.class);
        util.exportExcel(response, list, "终端信息数据");
    }

    /**
     * 获取终端信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{meterid}")
    public AjaxResult getInfo(@PathVariable("meterid") Long meterid) {
        return success(meterInfo2Service.selectMeterInfoByMeterid(meterid));
    }

    /**
     * 新增终端信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "终端信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeterInfo2 meterInfo2) {
        meterInfo2.setCreateBy(getUsername());
        meterInfo2.setCreateTime(DateUtils.getNowDate());
        return toAjax(meterInfo2Service.insertMeterInfo(meterInfo2));
    }

    /**
     * 修改终端信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "终端信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeterInfo2 meterInfo2) {
        meterInfo2.setUpdateBy(getUsername());
        meterInfo2.setUpdateTime(DateUtils.getNowDate());
        return toAjax(meterInfo2Service.updateMeterInfo(meterInfo2));
    }

    /**
     * 删除终端信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "终端信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{meterids}")
    public AjaxResult remove(@PathVariable Long[] meterids) {
        return toAjax(meterInfo2Service.deleteMeterInfoByMeterids(meterids));
    }
}
